package main

import (
	"log"
	"os"
	"os/exec"
)

var bashenv = []string{"DIR=/root/go/test/a", "sub=shell"}

func setEnv(key string, value string) {
	os.Setenv(key, value)
}

func execShellCmdWithEnv(cmd string, env []string) error {
	runCmd := exec.Command("/bin/bash", "-c", cmd)
	newEnv := append(os.Environ(), env...)
	log.Println(newEnv)
	runCmd.Env = newEnv
	runCmdOut, err := runCmd.CombinedOutput()
	if err != nil {
		log.Println(runCmd, "Failed", string(runCmdOut))
		return err
	} else {
		log.Println(runCmd, "Success", string(runCmdOut))
	}

	return nil
}

func main() {
	cmd := "$TOP_DIR/t.sh"
	env := []string{"TOP_DIR=./"}
	_ = execShellCmdWithEnv(cmd, env)
}

